/*********************************************************************************
  *Copyright(C),1996-2022,ChenJiehong
  *FileName:  pid.h
  *Author:  ChenJiehong
  *Version:  V1.0
  *Date: 2023-04-24
**********************************************************************************/

#ifndef  __pid_H__
#define  __pid_H__

/***************************************Includes***********************************/
 #include "stdint.h"


/***************************************Macros***********************************/



/***************************************Variables***********************************/
typedef struct
{
    uint16_t u16KP;  /**< Constant K, Proportional gain */
    uint16_t u16KI;  /**< Constant I, Integral gain */
    uint16_t u16KD;  /**< Constant D, Differential gain */
    int32_t i32Error_Sum;
    uint16_t Integral_LimitMax;
    int32_t i32Integral;  /**< PID filter integral value */
    int16_t i16LastError;  /**< Last error */

    uint16_t u16OutputLimitMax;  /**< Max value */
    uint16_t u16OutputLimitMin;  /**< Max value */
} FILTER_PID_Object_t;

typedef struct
{
    uint16_t u16KP;  /**< Constant K, Proportional gain */
    uint16_t u16KI;  /**< Constant I, Integral gain */
    uint16_t u16KD;  /**< Constant D, Differential gain */
    int16_t i16Deadband;
    int16_t i16Error;
    int16_t i16Error_Limit;
    int16_t i16Error_last;
    int16_t i16dError_last;
    uint16_t u16PID_Out;
    uint16_t u16Out_Limit;
} Incremental_PID_Object_t;



/***************************************Functions***********************************/
void filter_pid_Init (FILTER_PID_Object_t*  a_pHandler);
int16_t filter_pid_Handler (FILTER_PID_Object_t*  a_pHandler, int16_t a_i16Error);
void Incremental_PID_Init (uint16_t Init_out, Incremental_PID_Object_t*  a_pHandler);
uint16_t Incremental_PID_Handler(Incremental_PID_Object_t * a_pHandler, int16_t error);
#endif
/* [] END OF pid.h */
